(ns blade-art-online.user-test
 (:require [ring.util.response :refer [response]]
           [blade-art-online.user :refer :all]
           [clojure.test :refer :all]))

(def mock-request {:bodys {:name "Mike" :pass "12345"}})

(deftest test-handle-register
 (is 
  (=
   (response {:ok true})
   (handle-register 
    mock-request
    (fn [{:keys [name pass]}] (prn (str "name: " name " pass: " pass))))))
 (is
  (=
   (response {:ok false :msg "Register error: Server not started."})
   (handle-register 
    mock-request 
    (fn [{:keys [name pass]}] 
     (prn (str "name: " name " pass: " pass))
     (throw (Exception. "Server not started.")))))))

(deftest test-handle-login
 (is
  (=
   (assoc (response {:ok true}) :session {:login true})
   (handle-login
    mock-request
    (fn [{:keys [name pass]}] true)))))